<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    // function getLogisticsStatus(data) {
    //   const regex = /^([A-Z]{2,})-(\d{8})-(\d{1,})$/ // 正则表达式匹配格式

    //   const match = data.match(regex) // 使用正则表达式检查格式
    //   if (!match) {
    //     return null // 格式不正确，返回 null
    //   }
    //   console.log(match);

    //   const [ company, date, serialNumber] = match // 解构提取匹配到的结果
    //   return {
    //     company,
    //     date,
    //     serialNumber,
    //   }
    // }

    function getLogisticsStatus(data) {
      const res = data.split('-')
      if (res.length !== 3) {
        return null
      } else {
        const [company, date, serialNumber] = res
        return {
          company,
          date,
          serialNumber,
        }
      }
    }

    console.log(getLogisticsStatus('SF-20230217-000001'))
    // 输出：{ company: 'SF', date: '20230217', serialNumber: '000001' }

    console.log(getLogisticsStatus('YTO-20230217-000002'))
    // 输出：{ company: 'YTO', date: '20230217', serialNumber: '000002' }

    console.log(getLogisticsStatus('SF-20230217-000003-TEST'))
    // 输出：null

    console.log(getLogisticsStatus('SF-20230217'))
    // 输出：null

    console.log(getLogisticsStatus('SF-20230217000004'))
    // 输出：null
  </script>
</html>
